#include "DRWinTitle.h"
#include "ui_DRWinTitle.h"

DRWinTitle::DRWinTitle(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DRWinTitle)
{
    ui->setupUi(this);

    maxed = false;

    x = 0;
    y = 0;

    connect(ui->pushButtonMax, SIGNAL(clicked()), this, SLOT(maximum()));
    connect(ui->pushButtonMin, SIGNAL(clicked()), this, SLOT(minimum()));
    connect(ui->pushButtonClose, SIGNAL(clicked()), this, SIGNAL(onClose()));
}

DRWinTitle::~DRWinTitle()
{
    delete ui;
}


void DRWinTitle::mousePressEvent(QMouseEvent * event)
{
    this->pressed = true;
    x = 0;
    y = 0;
}

void DRWinTitle::mouseReleaseEvent(QMouseEvent * event)
{
    this->pressed = false;
    x = 0;
    y = 0;
}

void DRWinTitle::mouseDoubleClickEvent(QMouseEvent * event)
{
    maximum();
}

void DRWinTitle::mouseMoveEvent(QMouseEvent * event)
{
    if (x != 0 || y != 0)
    {
        emit onMove(event->globalX() - x, event->globalY() - y);
    }

    x = event->globalX();
    y = event->globalY();
}

void DRWinTitle::maximum()
{
    emit onMaximun(maxed);
    maxed = !maxed;
}

void DRWinTitle::minimum()
{
    emit onMinimum();
    maxed = false;
}
